package sample;

import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.Log;

/**
 * Created by Administrator on 2016/6/27.
 */
public class AdbDeviceManager extends Thread implements AndroidDebugBridge.IDebugBridgeChangeListener {
    public static final String ADB = "adb";
    private final AndroidDebugBridge.IDeviceChangeListener listener;

    public AdbDeviceManager(AndroidDebugBridge.IDeviceChangeListener listener) {
        this.listener = listener;
    }

    @Override
    public void run() {
        super.run();
        AndroidDebugBridge.createBridge(ADB, true);
        Log.d(ADB, "adb服务器开启" + AndroidDebugBridge.getSocketAddress().toString());
        AndroidDebugBridge.initIfNeeded(false);
        AndroidDebugBridge.addDeviceChangeListener(listener);
        AndroidDebugBridge.addDebugBridgeChangeListener(this);
    }

    @Override
    public void bridgeChanged(AndroidDebugBridge androidDebugBridge) {
        Log.d(ADB, "adb状态改变" + androidDebugBridge.getConnectionAttemptCount());
    }

}
